package com.dog.basics.common.photooss.properties;

import com.dog.basics.common.photooss.util.MinioUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * Minio文件上传配置文件
 */
@Data
@Configuration
@PropertySource("classpath:minio.properties")
@ConfigurationProperties(prefix = "minio")
public class MinioOSSProperties {
    private String minioUrl;
    private String minioName;
    private String minioPass;
    private String bucketName;

    @Bean
    public void initMinio() {
        if (!minioUrl.startsWith("http")) {
            minioUrl = "http://" + minioUrl;
        }
        if (!minioUrl.endsWith("/")) {
            minioUrl = minioUrl.concat("/");
        }
        MinioUtil.setMinioUrl(minioUrl);
        MinioUtil.setMinioName(minioName);
        MinioUtil.setMinioPass(minioPass);
        MinioUtil.setBucketName(bucketName);
    }

}
